package com.woniuxy.personal.core.service.impl;

import com.woniuxy.personal.core.model.PlOrder;
import com.woniuxy.personal.core.mapper.PlOrderMapper;
import com.woniuxy.personal.core.model.PlOrderitem;
import com.woniuxy.personal.core.service.PlOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.personal.core.vo.OrderVo;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author gmx
 * @since 2021-06-29
 */
@Service
public class PlOrderServiceImpl extends ServiceImpl<PlOrderMapper, PlOrder> implements PlOrderService {

    @Autowired
    PlOrderMapper plOrderMapper;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Override
    public String createOrder(OrderVo orderVo) {
        //生成订单编号
        String ordernumber = UUID.randomUUID().toString();
        //将订单数据发送到mq
        CorrelationData data = new CorrelationData();
        data.setId(ordernumber);
        rabbitTemplate.convertAndSend("order-exchange","order."+ordernumber,orderVo,data);
        rabbitTemplate.convertAndSend("ttl-exchange","ttl."+ordernumber,orderVo,data);
        return ordernumber;
    }

    @Override
    public List<OrderVo> selectOrder(int user_id) {
        return plOrderMapper.selectOrderList(user_id);
    }

    @Override
    public List<OrderVo> selectNonpaymentOrderList(int user_id) {
        return plOrderMapper.selectNonpaymentOrderList(user_id);
    }

    @Override
    public List<OrderVo> selectPaidOrderList(int user_id) {
        return plOrderMapper.selectPaidOrderList(user_id);
    }

    @Override
    public List<OrderVo> selectNonServiceOrderList(int user_id) {
        return plOrderMapper.selectNonServiceOrderList(user_id);
    }

    @Override
    public List<OrderVo> selectNonAppraiseOrderList(int user_id) {
        return plOrderMapper.selectNonAppraiseOrderList(user_id);
    }

    @Override
    public List<OrderVo> selectNonAfterServiceOrderList(int user_id) {
        return plOrderMapper.selectNonAfterServiceOrderList(user_id);
    }

    @Override
    public List<OrderVo> selectFinishedOrderList(int user_id) {
        return plOrderMapper.selectFinishedOrderList(user_id);
    }

    @Override
    public int payOrder(int id, int user_id) {
        return plOrderMapper.payOrder(id,user_id);
    }

    @Override
    public int confirm(int id, int user_id) {
        return plOrderMapper.confirm(id,user_id);
    }

    @Override
    public int cancelOrder(int user_id, int id) {
        return plOrderMapper.cancelOrder(user_id,id);
    }

    @Override
    public String selectOrderNumber(int id) {
        String orderNumber = this.plOrderMapper.selectOrderNumber(id);
        return orderNumber;
    }

    @Override
    public Date selectTimeByOrderId(Integer orderId) {
        Date time = this.plOrderMapper.seletTimeByOrderId(orderId);
        return time;
    }
}
